<template>
  <!--企业印章类型 新增/修改-->
  <uni-popup ref="modifySealType">
    <uni-popup-dialog
        type="info"
        cancelText="取消"
        confirmText="确认"
        :title="title"
        @close="cancel"
        @confirm="submitForm"
        before-close>
      <template v-slot="content">
        <view class="tip">
          <i class="iconfont colorIcon" style="margin-right: 10rpx;font-size: 26rpx;">&#xe70f;</i> 请按要求输入印章类型信息
        </view>
        <uni-forms
            ref="form"
            :modelValue="form"
            :rules="rules"
            :label-width="75" type="line" label-align="right"
            class="paddingAll">
          <uni-forms-item label="类型名称" name="name" required>
            <uni-easyinput placeholder="请输入印章类型名称" type="text" maxlength="50" v-model="form.name"/>
          </uni-forms-item>
          <uni-forms-item label="类型说明" name="remark">
            <uni-easyinput v-model="form.remark" type="textarea" maxlength="200"
                           placeholder="请输入印章类型说明，长度不超过200个汉字"/>
          </uni-forms-item>
        </uni-forms>
      </template>
    </uni-popup-dialog>
  </uni-popup>
</template>

<script>
import {addSealType, updateSealType} from "@/api/ec/console/seal/sealType";

export default {
  props: {},
  data() {
    return {
      // 企业信息
      companyInfo: this.$store.getters.companyInfo,
      // 标题
      title: '',
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: {rules: [{required: true, errorMessage: '请输入印章类型名称'}]},
      },
    };
  },
  methods: {
    /** 打开弹出框 */
    toOpenDialog(data) {
      if (!!data) {
        this.form = data;
        this.title = "修改印章类型";
      } else {
        this.form = {};
        this.title = "添加印章类型";
      }
      this.$refs.modifySealType.open('center')
    },
    /** 取消按钮 */
    cancel() {
      this.$refs.modifySealType.close()
    },
    /** 变更企业信息,确定按钮 */
    submitForm() {
      this.$refs.form.validate().then(valid => {
        if (valid) {
          this.$modal.loading();
          if (this.form.id != null) {
            updateSealType(this.form).then(response => {
              uni.hideLoading()
              this.$emit("success", "");
              this.$modal.msgSuccess("印章类型修改成功！");
              this.cancel();
            }).catch(() => {
              uni.hideLoading()
            });
          } else {
            addSealType(this.form).then(response => {
              uni.hideLoading()
              this.$emit("success", "");
              this.$modal.msgSuccess("印章类型修改成功！");
              this.cancel();
            }).catch(() => {
              uni.hideLoading()
            });
          }
        }
      });
    },
  }
};
</script>
<style scoped lang="scss">

::v-deep .uni-popup-dialog {
  width: 90%;
}

::v-deep .uni-dialog-content {
  padding: 20rpx;
  display: block;
}

.tip {
  background: #E6F6EF;
  padding: 15rpx;
  font-size: 22rpx;
  font-weight: 400;
  color: #555b65;
  line-height: 35rpx;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: baseline;
  -ms-flex-align: baseline;
  align-items: baseline;
  margin-bottom: 25rpx;
}

.show-text {
  color: #666;
  padding: 15rpx;
  background: #F7F6F6;

  i {
    font-size: 26rpx;
    margin-right: 10rpx;
  }

  span {
    font-size: 26rpx;
  }

  p {
    font-size: 26rpx;
    text-indent: 1rem;
  }
}

</style>
